package com.maoyu.cloud.login.controller;

import com.alibaba.fastjson.JSON;
import com.maoyu.cloud.login.entity.MenuLevelEntity;
import com.maoyu.cloud.mybatis.entity.PtMenuEntity;
import com.maoyu.cloud.user.service.LoginService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.List;

@Controller
public class MainController {

    @Resource
    private LoginService loginService;
    @RequestMapping("/")
    public String main(HttpServletRequest request){
        List<MenuLevelEntity> list = loginService.queryMenuLevelList();
        HttpSession session = request.getSession();
        session.setAttribute("menu",list);

        return "/sm/mainPage";
    }

    @RequestMapping("/homePage")
    public String homePage() {
        return "/sm/homePage";
    }

    @RequestMapping("/queryMenuList")
    @ResponseBody
    public String menuLevelEntity() {

        List<PtMenuEntity> ptMenuEntities = loginService.queryMenuInfoListByUuid();
        return JSON.toJSONString(ptMenuEntities);
    }

    @ResponseBody
    @RequestMapping("/queryMenuLevel")
    public String menu() {
        List<MenuLevelEntity> menuLevelEntities = loginService.queryMenuLevelList();
        return JSON.toJSONString(menuLevelEntities);
    }
}
